package com.healthyeating.manage.controller;

import com.healthyeating.common.annotation.Log;
import com.healthyeating.common.core.controller.BaseController;
import com.healthyeating.common.core.domain.AjaxResult;
import com.healthyeating.common.enums.BusinessType;
import com.healthyeating.manage.domain.Chat;
import com.healthyeating.manage.service.IDeepSeekService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/deepseek")
public class DeepSeekController extends BaseController {

    @Autowired
    private IDeepSeekService deepSeekService;

    /**
     * 聊天
     * @param request
     * @return
     */
    @PostMapping(value = "/chat/stream",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chatStream(HttpServletRequest request) {
        return deepSeekService.chatByStream(request);
    }

    /**
     * 查询对话记录列表
     */
    @GetMapping("/chat/list")
    public AjaxResult list(Chat chat) {
        return success(deepSeekService.selectChatList(chat));
    }

    /**
     * 查询对话记录
     */
    @GetMapping("/chat/{chatId}")
    public AjaxResult getChat(@PathVariable Long chatId) {
        return success(deepSeekService.selectChatByChatId(chatId));
    }

    /**
     * 新增对话记录
     * @param chat
     * @return 结果
     */
    @Log(title = "对话记录", businessType = BusinessType.INSERT)
    @PostMapping(value = "/chat/addChat")
    public AjaxResult addChat(@RequestBody Chat chat) {
        return toAjax(deepSeekService.addChat(chat));
    }

    /**
     * 修改对话记录
     * @param chat
     * @return 结果
     */
    @Log(title = "对话记录", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/chat/editChat")
    public AjaxResult edit(@RequestBody Chat chat) {
        return toAjax(deepSeekService.editChat(chat));
    }

    /**
     * 删除对话记录
     */
    @Log(title = "对话记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/chat/delChat/{chatId}")
    public AjaxResult remove(@PathVariable Long chatId) {
        return toAjax(deepSeekService.removeChat(chatId));
    }

}

